package com.tlxch.controller.teacher;

import com.tlxch.pojo.SGrades;
import com.tlxch.result.Result;
import com.tlxch.server.teacher.TSgradesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

@Api(tags = "成绩相关接口")
@Slf4j
@RestController
@RequestMapping("/teacher/grades")
public class TSgradeController {
    @Autowired
    TSgradesService tSgradesService;

    @PostMapping("/addstuGrades")
    @ApiOperation("添加学生成绩")
    public Result addstuGrades(@RequestBody SGrades sGrades){
        List<SGrades> sGradesList = tSgradesService.getBystuId(sGrades.getSgSid());
        int flage = 0;
        System.out.println(sGradesList.size());
        for (SGrades sGrades1 : sGradesList){
            System.out.println(sGrades1);
            if (Objects.equals(sGrades1.getSgSemester(), sGrades.getSgSemester())) {
                flage = 1;
                break;
            }
        }
        if (flage == 0){
            tSgradesService.addstuGrades(sGrades);
            return Result.success();
        }else {
            return Result.error("该学生本学期已存在成绩");
        }

    }
}
